<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row  >
        <!-- <el-col :span="12">
            <el-form-item label="往来单位类型" prop="correspondentType"
                :rules="[{required: true, message:'往来单位类型不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.correspondentType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('correspondent_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="单位名称" prop="companyName"
                :rules="[{required: true, message:'单位名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.companyName" placeholder="请填写单位名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="往来单位编号" prop="correspondentNo"
                :rules="[{required: true, message:'往来单位编号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.correspondentNo" placeholder="请填写往来单位编号"     ></el-input>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="证件类型" prop="cerType"
                :rules="[{required: true, message:'证件类型不能为空', trigger:'blur'}
                 ]">
                   <el-select v-model="inputForm.cerType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('cer_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="证件号码" prop="taxpayerIdentificationNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.taxpayerIdentificationNo" placeholder="请填写纳税人识别号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位性质" prop="taxpayerType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.taxpayerType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('taxpayer_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="地址" prop="address"
                :rules="[
                 ]">
              <el-input v-model="inputForm.address" placeholder="请填写地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="法定代表人" prop="legalRepresentative"
                :rules="[
                 ]">
              <el-input v-model="inputForm.legalRepresentative" placeholder="请填写法定代表人"     ></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="所在区域" prop="area"
                :rules="[
                 ]">
                <area-select v-model="inputForm.area"/>
           </el-form-item>
        </el-col> -->
   
        <el-col :span="12">
            <el-form-item label="电话 " prop="phone"
                :rules="[
                  {required: true, message:'电话不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写电话 "     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="负责人" prop="leader"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leader" placeholder="请填写负责人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="负责人电话" prop="leaderPhone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.leaderPhone" placeholder="请填写负责人电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开户行" prop="bankOfDeposit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.bankOfDeposit" placeholder="请填写负责人电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="账户" prop="accountNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.accountNumber" placeholder="请填写负责人电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="成立日期" prop="establishmentDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.establishmentDate"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="注册资本" prop="registeredCapital"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registeredCapital" placeholder="请填写注册资本"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="公司类型" prop="companyType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.companyType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('company_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价等级" prop="evaluationGrade"
                :rules="[
                 ]">
                <el-select v-model="inputForm.evaluationGrade" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('evaluation_grade')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="公司简介" prop="companyProfile"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.companyProfile" placeholder="请填写公司简介"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="经营范围" prop="businessScope"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.businessScope" placeholder="请填写经营范围"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <template #footer>    
        <span class="dialog-footer">
          <el-button @click="visible = false" icon="circle-close">关闭</el-button>
          <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import AreaSelect from '@/components/areaSelect'
  import correspondentService from '@/api/correspondent/correspondentService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          correspondentType: '',
          companyName: '',
          taxpayerIdentificationNo: '',
          taxpayerType: '',
          legalRepresentative: '',
          area: '',
          address: '',
          phone: '',
          bankOfDeposit: '',
          accountNumber: '',
          establishmentDate: null,
          registeredCapital: '',
          companyType: '',
          evaluationGrade: '',
          companyProfile: '',
          businessScope: ''
        }
      }
    },
    components: {
      AreaSelect
    },
    created () {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建往来单位`
        } else if (method === 'edit') {
          this.title = '修改往来单位'
        } else if (method === 'view') {
          this.title = '查看往来单位'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            correspondentService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            correspondentService.save(this.inputForm).then((data) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

  
